package com.grm.flowable.controller;

import com.grm.common.Result;
import com.grm.flowable.entity.ApproveRejectVO;
import com.grm.flowable.entity.AskForLeave;
import com.grm.flowable.service.AskForLeaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 处理请假申请
 *
 * @author gaorimao
 * @date 2022/08/18
 */
@RestController
@RequestMapping("/flowable/test")
public class AskForLeaveController {
    @Autowired
    private AskForLeaveService askForLeaveService;

    /**
     * 提交任务
     */
    @PostMapping("/askForLeave/submit")
    public Result askForLeave(@RequestBody AskForLeave askForLeave) {
        return askForLeaveService.askForLeave(askForLeave);
    }

    /**
     * 查询我要审批的任务列表
     */
    @GetMapping("/askForLeave/apply/leaveList")
    public Result applyLeaveList(@RequestParam String identity) {
        List<Map<String, Object>> list =  askForLeaveService.leaveList(identity);
        return Result.success("查询我要审批的任务列表成功！",list);
    }

    /**
     * 审批：同意/拒绝
     */
    @PostMapping("/askForLeave/review")
    public Result askForLeaveHandler(@RequestBody ApproveRejectVO approveRejectVO) {
        return askForLeaveService.askForLeaveHandler(approveRejectVO);
    }

    /**
     * 根据用户名查询自己提交的任务审批情况
     */
    @GetMapping("/askForLeave/queryMyTasks")
    public Result searchResult(@RequestParam String name) {
        return askForLeaveService.searchResult(name);
    }
}
